package mcu.market.util;

import java.util.ArrayList;
import java.util.Map;

import mcu.market.ibatis.IBatisFactory;

public class DBControl{
	public static void main(String[] args) {
		
	}
	public ArrayList SelectResultList(String sql_mapping,Map condition){
		return (ArrayList)SelectResult(sql_mapping,condition);
	}
	public ArrayList SelectResultList(String sql_mapping,Object condition){
		if(condition.getClass().getPackage().getName().equals("mcu.market.ibatis.bean")){;
			return (ArrayList)SelectResult(sql_mapping,condition);
		}else{
			ClassCastException e=new ClassCastException("Class just in mcu.market.ibatis.bean");
			e.printStackTrace();
		}
		return null;
	}
	public Object SelectOne(String sql_mapping,Map condition){
		return SelectOne(sql_mapping,condition);
	}
	public Object SelectOne(String sql_mapping,Object condition){
		Object obj= IBatisFactory.getInstance().getSqlSession().selectOne(sql_mapping, condition);
		IBatisFactory.getInstance().getSqlSession().close();
		return obj;
	}
	
	/**
	 * 內部result
	 * @param sql_mapping
	 * @param condition
	 * @return
	 */
	private Object SelectResult(String sql_mapping,Object condition) {
		Object obj= IBatisFactory.getInstance().getSqlSession().selectList(sql_mapping, condition);
		IBatisFactory.getInstance().getSqlSession().close();
		return obj;
	}
}
